package com.google.android.material.button;

import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Build;
import b.f.l.s;
import c.b.a.b.b;
import c.b.a.b.c0.g;
import c.b.a.b.c0.k;
import c.b.a.b.c0.n;
import c.b.a.b.l;
import c.b.a.b.z.c;
import com.google.android.material.internal.h;

class a {
    private static final boolean s = (Build.VERSION.SDK_INT >= 21);

    /* renamed from: a  reason: collision with root package name */
    private final MaterialButton f2207a;

    /* renamed from: b  reason: collision with root package name */
    private k f2208b;

    /* renamed from: c  reason: collision with root package name */
    private int f2209c;

    /* renamed from: d  reason: collision with root package name */
    private int f2210d;
    private int e;
    private int f;
    private int g;
    private int h;
    private PorterDuff.Mode i;
    private ColorStateList j;
    private ColorStateList k;
    private ColorStateList l;
    private Drawable m;
    private boolean n = false;
    private boolean o = false;
    private boolean p = false;
    private boolean q;
    private LayerDrawable r;

    a(MaterialButton materialButton, k kVar) {
        this.f2207a = materialButton;
        this.f2208b = kVar;
    }

    private void A(k kVar) {
        if (d() != null) {
            d().setShapeAppearanceModel(kVar);
        }
        if (l() != null) {
            l().setShapeAppearanceModel(kVar);
        }
        if (c() != null) {
            c().setShapeAppearanceModel(kVar);
        }
    }

    private void C() {
        g d2 = d();
        g l2 = l();
        if (d2 != null) {
            d2.a0((float) this.h, this.k);
            if (l2 != null) {
                l2.Z((float) this.h, this.n ? c.b.a.b.s.a.c(this.f2207a, b.colorSurface) : 0);
            }
        }
    }

    private InsetDrawable D(Drawable drawable) {
        return new InsetDrawable(drawable, this.f2209c, this.e, this.f2210d, this.f);
    }

    private Drawable a() {
        g gVar = new g(this.f2208b);
        gVar.L(this.f2207a.getContext());
        androidx.core.graphics.drawable.a.o(gVar, this.j);
        PorterDuff.Mode mode = this.i;
        if (mode != null) {
            androidx.core.graphics.drawable.a.p(gVar, mode);
        }
        gVar.a0((float) this.h, this.k);
        g gVar2 = new g(this.f2208b);
        gVar2.setTint(0);
        gVar2.Z((float) this.h, this.n ? c.b.a.b.s.a.c(this.f2207a, b.colorSurface) : 0);
        if (s) {
            g gVar3 = new g(this.f2208b);
            this.m = gVar3;
            androidx.core.graphics.drawable.a.n(gVar3, -1);
            RippleDrawable rippleDrawable = new RippleDrawable(c.b.a.b.a0.b.d(this.l), D(new LayerDrawable(new Drawable[]{gVar2, gVar})), this.m);
            this.r = rippleDrawable;
            return rippleDrawable;
        }
        c.b.a.b.a0.a aVar = new c.b.a.b.a0.a(this.f2208b);
        this.m = aVar;
        androidx.core.graphics.drawable.a.o(aVar, c.b.a.b.a0.b.d(this.l));
        LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{gVar2, gVar, this.m});
        this.r = layerDrawable;
        return D(layerDrawable);
    }

    private g e(boolean z) {
        LayerDrawable layerDrawable = this.r;
        if (layerDrawable == null || layerDrawable.getNumberOfLayers() <= 0) {
            return null;
        }
        return (g) (s ? (LayerDrawable) ((InsetDrawable) this.r.getDrawable(0)).getDrawable() : this.r).getDrawable(z ^ true ? 1 : 0);
    }

    private g l() {
        return e(true);
    }

    /* access modifiers changed from: package-private */
    public void B(int i2, int i3) {
        Drawable drawable = this.m;
        if (drawable != null) {
            drawable.setBounds(this.f2209c, this.e, i3 - this.f2210d, i2 - this.f);
        }
    }

    /* access modifiers changed from: package-private */
    public int b() {
        return this.g;
    }

    public n c() {
        LayerDrawable layerDrawable = this.r;
        if (layerDrawable == null || layerDrawable.getNumberOfLayers() <= 1) {
            return null;
        }
        return (n) (this.r.getNumberOfLayers() > 2 ? this.r.getDrawable(2) : this.r.getDrawable(1));
    }

    /* access modifiers changed from: package-private */
    public g d() {
        return e(false);
    }

    /* access modifiers changed from: package-private */
    public ColorStateList f() {
        return this.l;
    }

    /* access modifiers changed from: package-private */
    public k g() {
        return this.f2208b;
    }

    /* access modifiers changed from: package-private */
    public ColorStateList h() {
        return this.k;
    }

    /* access modifiers changed from: package-private */
    public int i() {
        return this.h;
    }

    /* access modifiers changed from: package-private */
    public ColorStateList j() {
        return this.j;
    }

    /* access modifiers changed from: package-private */
    public PorterDuff.Mode k() {
        return this.i;
    }

    /* access modifiers changed from: package-private */
    public boolean m() {
        return this.o;
    }

    /* access modifiers changed from: package-private */
    public boolean n() {
        return this.q;
    }

    /* access modifiers changed from: package-private */
    public void o(TypedArray typedArray) {
        this.f2209c = typedArray.getDimensionPixelOffset(l.MaterialButton_android_insetLeft, 0);
        this.f2210d = typedArray.getDimensionPixelOffset(l.MaterialButton_android_insetRight, 0);
        this.e = typedArray.getDimensionPixelOffset(l.MaterialButton_android_insetTop, 0);
        this.f = typedArray.getDimensionPixelOffset(l.MaterialButton_android_insetBottom, 0);
        if (typedArray.hasValue(l.MaterialButton_cornerRadius)) {
            int dimensionPixelSize = typedArray.getDimensionPixelSize(l.MaterialButton_cornerRadius, -1);
            this.g = dimensionPixelSize;
            u(this.f2208b.w((float) dimensionPixelSize));
            this.p = true;
        }
        this.h = typedArray.getDimensionPixelSize(l.MaterialButton_strokeWidth, 0);
        this.i = h.c(typedArray.getInt(l.MaterialButton_backgroundTintMode, -1), PorterDuff.Mode.SRC_IN);
        this.j = c.a(this.f2207a.getContext(), typedArray, l.MaterialButton_backgroundTint);
        this.k = c.a(this.f2207a.getContext(), typedArray, l.MaterialButton_strokeColor);
        this.l = c.a(this.f2207a.getContext(), typedArray, l.MaterialButton_rippleColor);
        this.q = typedArray.getBoolean(l.MaterialButton_android_checkable, false);
        int dimensionPixelSize2 = typedArray.getDimensionPixelSize(l.MaterialButton_elevation, 0);
        int C = s.C(this.f2207a);
        int paddingTop = this.f2207a.getPaddingTop();
        int B = s.B(this.f2207a);
        int paddingBottom = this.f2207a.getPaddingBottom();
        this.f2207a.setInternalBackground(a());
        g d2 = d();
        if (d2 != null) {
            d2.T((float) dimensionPixelSize2);
        }
        s.r0(this.f2207a, C + this.f2209c, paddingTop + this.e, B + this.f2210d, paddingBottom + this.f);
    }

    /* access modifiers changed from: package-private */
    public void p(int i2) {
        if (d() != null) {
            d().setTint(i2);
        }
    }

    /* access modifiers changed from: package-private */
    public void q() {
        this.o = true;
        this.f2207a.setSupportBackgroundTintList(this.j);
        this.f2207a.setSupportBackgroundTintMode(this.i);
    }

    /* access modifiers changed from: package-private */
    public void r(boolean z) {
        this.q = z;
    }

    /* access modifiers changed from: package-private */
    public void s(int i2) {
        if (!this.p || this.g != i2) {
            this.g = i2;
            this.p = true;
            u(this.f2208b.w((float) i2));
        }
    }

    /* access modifiers changed from: package-private */
    public void t(ColorStateList colorStateList) {
        if (this.l != colorStateList) {
            this.l = colorStateList;
            if (s && (this.f2207a.getBackground() instanceof RippleDrawable)) {
                ((RippleDrawable) this.f2207a.getBackground()).setColor(c.b.a.b.a0.b.d(colorStateList));
            } else if (!s && (this.f2207a.getBackground() instanceof c.b.a.b.a0.a)) {
                ((c.b.a.b.a0.a) this.f2207a.getBackground()).setTintList(c.b.a.b.a0.b.d(colorStateList));
            }
        }
    }

    /* access modifiers changed from: package-private */
    public void u(k kVar) {
        this.f2208b = kVar;
        A(kVar);
    }

    /* access modifiers changed from: package-private */
    public void v(boolean z) {
        this.n = z;
        C();
    }

    /* access modifiers changed from: package-private */
    public void w(ColorStateList colorStateList) {
        if (this.k != colorStateList) {
            this.k = colorStateList;
            C();
        }
    }

    /* access modifiers changed from: package-private */
    public void x(int i2) {
        if (this.h != i2) {
            this.h = i2;
            C();
        }
    }

    /* access modifiers changed from: package-private */
    public void y(ColorStateList colorStateList) {
        if (this.j != colorStateList) {
            this.j = colorStateList;
            if (d() != null) {
                androidx.core.graphics.drawable.a.o(d(), this.j);
            }
        }
    }

    /* access modifiers changed from: package-private */
    public void z(PorterDuff.Mode mode) {
        if (this.i != mode) {
            this.i = mode;
            if (d() != null && this.i != null) {
                androidx.core.graphics.drawable.a.p(d(), this.i);
            }
        }
    }
}
